#define _CRT_SECURE_NO_WARNINGS 1
#include"stack.h"
#include<stdio.h>
#include<stdlib.h>
#include<assert.h>
//int main()
//{
//	int i = 0;
//	for (i = 0; i < 10; i++)
//	{
//		printf("%d ", i);
//	}
//	return 0;
//}
void stinit(st* pst)
{
	assert(pst);
	pst->a = NULL;
	pst->capacity = 0;
	pst->top = 0;
}

void stdestory(st* pst)
{
	assert(pst);
	free(pst->a);
	pst->a = NULL;
	pst->top = pst->capacity = 0;
}
void stpush(st* pst, stdatatype x)
{
	assert(pst);
	if (pst->top == pst->capacity)
	{
		int newcapacity = pst->capacity == 0 ? 4 : pst->capacity * 2;
		stdatatype* temp = (stdatatype*)realloc(pst->a, 2 * sizeof(stdatatype));
		if (temp == NULL)
		{
			perror("realloc fail!");
			return;
		}
		pst->capacity = newcapacity;
		pst->a = temp;
	}
	pst->a[pst->top] = x;
	pst->top++;
}
void stpop(st* pst)
{
	assert(pst);
	assert(pst->top > 0);
	pst->top--;
}
stdatatype sttop(st* pst)
{
	assert(pst);
	assert(pst->top > 0);
	return pst->a[pst->top - 1];
}
bool empty(st* pst)
{
	assert(pst);
	return pst->top == 0;
}

int stsize(st* pst)
{
	assert(pst);
	return pst->top;
}
int main()
{
	st st1;
	stinit(&st1);
	stpush(&st1, 1);
	stdatatype x1 = sttop(&st1);
	printf("%d\n", x1);
	stpush(&st1, 2);
	stdatatype x2 = sttop(&st1);
	printf("%d\n", x2);
	stpush(&st1, 3);
	stdatatype x3 = sttop(&st1);
	printf("%d\n", x3);
	stpush(&st1, 4);
	stdatatype x5 = sttop(&st1);
	printf("%d\n", x5);
	stpush(&st1, 5);
	stpop(&st1);
	stpop(&st1);
	stpop(&st1);
	stpop(&st1);
	//stpop(&st1);
	stdatatype x6 = sttop(&st1);
	printf("%d\n", x6);
	return 0;
}